import { createRouter, createWebHashHistory } from "vue-router";
import Layout from '@/layout/default/index.vue'

const routes = [
    {
        path: '/',
        component: () => Layout,
        children: [
            {
                path: '',
                component: () => import('@/views/home/index.vue'),
                meta: {
                    title: '首页',
                    keepAlive: true,
                }
            },
            {
                path: 'about',
                component: () => import('@/views/about/index.vue'),
                meta: {
                    title: '关于'
                }
            },
        ]
    },
    {
        path: '/login',
        component: () => import('@/views/login/index.vue'),
        meta: {
            title: '登录'
        }
    },
    {
        path: '/403',
        component: () => import('@/views/error/403/403.vue'),
        meta: {
            title: '403禁止访问'
        }
    },
    {
        path: '/:pathMatch(.*)*',
        component: () => import('@/views/error/404/404.vue'),
        meta: {
            title: '404'
        }
    }
]



const router = createRouter({
    history: createWebHashHistory(),
    routes
})

const whiteList = ['/login', '/404', '/', '/403']
// 403 禁止访问
router.beforeEach((to,from) => {
    // console.log('....')
    // if (whiteList.includes(to.path)) {
    //     return true
    // } else {
    //     return '/403'
    // }
    return true
})

export function setup(app) {
    app.use(router)
}